﻿/**
* Request the OWNER and OWNER's friends.
*/
function request() {
	alert("oh!");
	//console.log(osapi);
	// osapi.people.getViewer().execute(function(viewer) {
		// console.log(viewer);
		// var html = 'Your name is ' + viewer.name.givenName + ' ' + viewer.name.familyName + '!';
		// html+="<a href='"+ viewer.profileUrl +"' target='_blank'>";
		// html+= "<img src='"+ viewer.thumbnailUrl +"' style='float: left;' />";
		// html+="</a>";
		// document.getElementById('message').innerHTML = html;
	// });
	// osapi.people.get({userId: '@owner', groupId: '@friends'}).execute(function(ownerFriends) {
		// console.log(ownerFriends);
		// var html = 'You have ' + ownerFriends.totalResults + ' friends';
		// html+="<ul>";
		// var list = ownerFriends.list;
		// for(var i=0, j=list.length;i<j;i++){
			// console.log(list[i]);
			// html +="<li>"+ list[i].displayName + "</li>";
		// }
		// html+="</ul>";
		// document.getElementById('message').innerHTML = html;
	// });
	// osapi.activities.get({userId: '@viewer', groupId: '@friends', count: 20}).execute(function(activities){
		// console.log(activities);
		// // var html = 'You have ' + ownerFriends.totalResults + ' friends';
		// // document.getElementById('message').innerHTML = html;
	// });
	// osapi.activities.create({userId: '@viewer', activity: {title: 'Hello!', url: 'http://mysite.com'}}).execute(function(){
		// console.log(arguments);
	// });
	// osapi.appdata.get({userId: '@viewer', groupId: '@friends', keys: ['gifts']}).execute(function(){
		// console.log(arguments);
	// });
	// osapi.appdata.update({userId: '@viewer', data: {gifts: 'a crazed monkey'}}).execute(function(){
		// console.log(arguments);
	// });

	// var batch = osapi.newBatch()
	// .add("viewer", osapi.people.getViewer())
    // .add('activities', osapi.activities.get({ userId : '@viewer', groupId : '@self'}))
	// .execute(function(result) {
		// console.log(result);
		// alert('hi, ' + result.viewer.displayName + '!');
		// //alert('you have ' + result.activities.length + ' activities.');
	// });
	
	// var result = osapi.http.get("http://172.0.0.1/",{format:"html"}).execute(function(){
		// console.log(arguments);
	// });
	//gadgets.log("haha!");
	// gadgets.io.makeRequest("http://172.0.0.1:8080/",function(){
		// console.log(arguments);
	// });
	//console.log(gadgets);
	//var view = gadgets.views.getCurrentView();
	//console.log(view);

};

/**
* Parses the response and generates html to list the names of the owner and
* his or her friends.
*
* @param {Object} dataResponse Friend information that was requested.
*/
function response(dataResponse) {
  // var owner = dataResponse.get('get_owner').getData();
  // var friends = dataResponse.get('get_friends').getData(); 
  // var html = 'Friends of ' + owner.getDisplayName();
  // html += ':<br><ul>';
  // friends.each(function(person) {
      // html += '<li>' + person.getDisplayName() + '</li>';
  // });
  // html += '</ul>';
  // document.getElementById('message').innerHTML = html;
};
// Execute the request function when the application is finished loading.
gadgets.util.registerOnLoadHandler(request);